/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 script_target_type.cpp

	$Header: /heroes4/script_target_type.cpp $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "script_target_type.h"

#include "script_context.h"

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool is_valid( t_script_context context, t_script_stack_target target )
{
	assert( context >= 0 && context < k_script_context_count );
	assert( target >= 0 && target < k_script_stack_target_count );

	static bool const k_valid[ k_script_context_count ][ k_script_stack_target_count ] =
	{
		{ // k_script_context_hero
			true,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_hero_in_combat
			true,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			true,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_town
			false,	// k_script_stack_target_this
			false,	// k_script_stack_target_this_army
			true,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_town_in_combat
			false,	// k_script_stack_target_this
			false,	// k_script_stack_target_this_army
			true,	// k_script_stack_target_garrison
			true,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_town_with_visitor
			false,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			true,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_placed_event
			false,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_global
			false,	// k_script_stack_target_this
			false,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_seers_hut
			false,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_quest_guard
			false,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_quest_gate
			false,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_army
			false,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_army_in_combat
			false,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			true,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_ownable
			false,	// k_script_stack_target_this
			false,	// k_script_stack_target_this_army
			false,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ //	k_script_context_garrison
			false,	// k_script_stack_target_this
			false,	// k_script_stack_target_this_army
			true,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_garrison_in_combat
			false,	// k_script_stack_target_this
			false,	// k_script_stack_target_this_army
			true,	// k_script_stack_target_garrison
			true,	// k_script_stack_target_opposing_army
		},
		{ // k_script_context_garrison_with_visitor
			false,	// k_script_stack_target_this
			true,	// k_script_stack_target_this_army
			true,	// k_script_stack_target_garrison
			false,	// k_script_stack_target_opposing_army
		},
	};

	return k_valid[ context ][ target ];
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool is_valid( t_script_context context, t_script_hero_target target )
{
	assert( context >= 0 && context < k_script_context_count );
	assert( target >= 0 && target < k_script_hero_target_count );

	static bool const k_valid[ k_script_context_count ][ k_script_hero_target_count ] =
	{
		{ // k_script_context_hero
			true,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_hero_in_combat
			true,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			true,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			true,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			true,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_town
			false,	// k_script_hero_target_this
			false,	// k_script_hero_target_this_army_any
			true,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			false,	// k_script_hero_target_this_army_most_powerful
			true,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			false,	// k_script_hero_target_this_army_least_powerful
			true,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_town_in_combat
			false,	// k_script_hero_target_this
			false,	// k_script_hero_target_this_army_any
			true,	// k_script_hero_target_garrison_any
			true,	// k_script_hero_target_opposing_army_any
			false,	// k_script_hero_target_this_army_most_powerful
			true,	// k_script_hero_target_garrison_most_powerful
			true,	// k_script_hero_target_opposing_army_most_powerful
			false,	// k_script_hero_target_this_army_least_powerful
			true,	// k_script_hero_target_garrison_least_powerful
			true,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_town_with_visitor
			false,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			true,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			true,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			true,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_placed_event
			false,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_global
			false,	// k_script_hero_target_this
			false,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			false,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			false,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_seers_hut
			false,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_quest_guard
			false,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_quest_gate
			false,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_army
			false,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_army_in_combat
			false,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			true,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			true,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			true,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_ownable
			false,	// k_script_hero_target_this
			false,	// k_script_hero_target_this_army_any
			false,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			false,	// k_script_hero_target_this_army_most_powerful
			false,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			false,	// k_script_hero_target_this_army_least_powerful
			false,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ //	k_script_context_garrison
			false,	// k_script_hero_target_this
			false,	// k_script_hero_target_this_army_any
			true,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			false,	// k_script_hero_target_this_army_most_powerful
			true,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			false,	// k_script_hero_target_this_army_least_powerful
			true,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_garrison_in_combat
			false,	// k_script_hero_target_this
			false,	// k_script_hero_target_this_army_any
			true,	// k_script_hero_target_garrison_any
			true,	// k_script_hero_target_opposing_army_any
			false,	// k_script_hero_target_this_army_most_powerful
			true,	// k_script_hero_target_garrison_most_powerful
			true,	// k_script_hero_target_opposing_army_most_powerful
			false,	// k_script_hero_target_this_army_least_powerful
			true,	// k_script_hero_target_garrison_least_powerful
			true,	// k_script_hero_target_opposing_army_least_powerful
		},
		{ // k_script_context_garrison_with_visitor
			false,	// k_script_hero_target_this
			true,	// k_script_hero_target_this_army_any
			true,	// k_script_hero_target_garrison_any
			false,	// k_script_hero_target_opposing_army_any
			true,	// k_script_hero_target_this_army_most_powerful
			true,	// k_script_hero_target_garrison_most_powerful
			false,	// k_script_hero_target_opposing_army_most_powerful
			true,	// k_script_hero_target_this_army_least_powerful
			true,	// k_script_hero_target_garrison_least_powerful
			false,	// k_script_hero_target_opposing_army_least_powerful
		},
	};

	return k_valid[ context ][ target ];
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool is_valid( t_script_context context, t_script_army_target target )
{
	assert( context >= 0 && context < k_script_context_count );
	assert( target >= 0 && target < k_script_army_target_count );

	static bool const k_valid[ k_script_context_count ][ k_script_stack_target_count ] =
	{
		{ // k_script_context_hero
			true,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_hero_in_combat
			true,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			true,	// k_script_army_target_opposing
		},
		{ // k_script_context_town
			false,	// k_script_army_target_this
			true,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_town_in_combat
			false,	// k_script_army_target_this
			true,	// k_script_army_target_garrison
			true,	// k_script_army_target_opposing
		},
		{ // k_script_context_town_with_visitor
			true,	// k_script_army_target_this
			true,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_placed_event
			true,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_global
			false,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_seers_hut
			true,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_quest_guard
			true,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_quest_gate
			true,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_army
			true,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_army_in_combat
			true,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			true,	// k_script_army_target_opposing
		},
		{ // k_script_context_ownable
			false,	// k_script_army_target_this
			false,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_garrison
			false,	// k_script_army_target_this
			true,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
		{ // k_script_context_garrison_in_combat
			false,	// k_script_army_target_this
			true,	// k_script_army_target_garrison
			true,	// k_script_army_target_opposing
		},
		{ // k_script_context_garrison_with_visitor
			true,	// k_script_army_target_this
			true,	// k_script_army_target_garrison
			false,	// k_script_army_target_opposing
		},
	};

	return k_valid[ context ][ target ];
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool is_valid( t_script_context context, t_script_player_target target )
{
	assert( context >= 0 && context < k_script_context_count );
	assert( target >= 0 && target < k_script_player_target_count );

	if ( target >= k_script_player_target_specific )
		return true;

	static bool const k_valid[ k_script_context_count ][ k_script_player_target_specific ] =
	{
		{ // k_script_context_hero
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_hero_in_combat
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			true,	// k_script_player_target_opposing,
		},
		{ // k_script_context_town
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_town_in_combat
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			true,	// k_script_player_target_opposing,
		},
		{ // k_script_context_town_with_visitor
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_placed_event
			false,	// k_script_player_target_owner,
			true,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_global
			false,	// k_script_player_target_owner,
			true,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_seers_hut
			false,	// k_script_player_target_owner,
			true,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_quest_guard
			false,	// k_script_player_target_owner,
			true,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_quest_gate
			false,	// k_script_player_target_owner,
			true,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_army
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_army_in_combat
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			true,	// k_script_player_target_opposing,
		},
		{ // k_script_context_ownable
			true,	// k_script_player_target_owner,
			true,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_garrison
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
		{ // k_script_context_garrison_in_combat
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			true,	// k_script_player_target_opposing,
		},
		{ // k_script_context_garrison_with_visitor
			true,	// k_script_player_target_owner,
			false,	// k_script_player_target_current,
			false,	// k_script_player_target_opposing,
		},
	};

	return k_valid[ context ][ target ];
}
